﻿@{
    Layout = "~/Views/Shared/_Layout_List.cshtml";
}
@section toolbar{
    @*<a id="downloadTemplate" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">下载导入模板</a>*@
}
<form id="dataForm" enctype="multipart/form-data" class="easyui-form" method="post" data-options="novalidate:true">
    <table class="table_base">
        <colgroup>
            <col style="width:80px;" />
        </colgroup>
        <tbody>
            <tr>
                <th>文件</th>
                <td>
                    <input style="display:none" id="file" type="file" accept="*">
                    <input id="file-display" class="easyui-textbox" data-options="width:'200px',required:true">
                    <label for="file" class="easyui-linkbutton" data-options="iconCls:'icon-add'">选择文件</label>
                </td>
            </tr>
        </tbody>
    </table>
</form>
@section foottoolbar{
    <a id="saveForm" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-save'">上传</a>
}
<script>
    $(function () {
        document.getElementById('file').onchange = function () {
            $('#file').getFileBase64(function (base64, fileName) {
                $('#file-display').textbox('setValue', fileName);
            });
        };

        $('#saveForm').click(function () {
            if (!$('#dataForm').form('enableValidation').form('validate'))
                return;

            var formValues = $('#dataForm').getValues();
            loading();
            $('#file').getFileBase64(function (base64, fileName) {
                $.postJSON('/Demo/UploadFile', { fileName: fileName, fileBase64: base64 }, function (resJson) {
                    loading(false);

                    if (resJson.Success) {
                        parent.dialogMsg('上传成功!');
                        parent.$('#dataTable').datagrid('clearChecked').datagrid('reload');
                        parent.dialogClose('UploadFileForm');
                    }
                    else {
                        dialogError(resJson.Msg);
                    }
                });
            });
        });
    });
</script>
